package com.cjs.MyProxy;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class TestProxy {
	public static void main(String[] args) {
		Action action = (Action) MyProxy.getProxyInstance(Action.class.getClassLoader(), new Class[]{Action.class}, new Invocation(new Action() {
			public String execute(Object obj) {
				System.out.println(obj);
				return (String) obj;
			}
		}));
		System.out.println(action.execute("haha"));
	}
}

class Invocation implements MyInvocationHanlder{
	Object obj;
	public Invocation(){
		
	}
	
	public Invocation(Object obj){
		this.obj = obj;
	}
	public Object invoke(Object proxy, Method method, Object... args) {
		Object returnObj = null;
		try {
			returnObj = method.invoke(obj, args);
		} catch (IllegalAccessException e) {
			e.printStackTrace();
		} catch (IllegalArgumentException e) {
			e.printStackTrace();
		} catch (InvocationTargetException e) {
			e.printStackTrace();
		}
		return returnObj;
	}
	
}
